package cn.mxb.logic.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import cn.mxb.floor.pagination.Result;
import cn.mxb.floor.web.BaseAction;
import cn.mxb.logic.entity.SysCount;
import cn.mxb.logic.service.ISysCountService;

@SuppressWarnings({ "serial", "rawtypes" })
public class SysCountAction extends BaseAction implements Preparable,ModelDriven {
	protected static final String List_JSP = "/WEB-INF/page/web/floor/countList.jsp";
	protected static final String ADD_JSP = "/WEB-INF/page/web/floor/countAdd.jsp";
	protected static final String UPDATE_JSP = "/WEB-INF/page/web/floor/countUpdate.jsp";
	
	private SysCount sysCount;
	@Autowired
	private ISysCountService sysCountService;
	
	private Result<SysCount> pageResult;
	
	private List<SysCount> sysCountAllList; 
	
	/**
	 * @return_type: String
	 * @file_name: 跳转添加界面
	 */
	public String openAdd(){
		
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	
	/**
	 * 添加
	 * @return_type: String
	 */
	public String add(){
		sysCountService.add(sysCount);
		return openList();		
	}
	
	/**
	 * @file_name 打开列表
	 * @return 
	 */
	public String openList(){
		try{
			pageResult = sysCountService.find(sysCount, getPage(), getRow());
			setForwardView(List_JSP);
			return SUCCESS;
		}catch(Exception e){
			System.out.println(e);
		}
		return SUCCESS;
	}
	
	/**
	 * @file_name:删除 
	 */
	public String delete(){
		sysCountService.delete(sysCount.getId());
		return openList();
	}
	
	/**
	 * @return_type: 
	 * @file_name:  打开修改页面
	 */
	public String openUpdate(){
		sysCount =  sysCountService.findByProperty("id",sysCount.getId()+"");
		setForwardView(UPDATE_JSP);
		return SUCCESS;
		
	}
	
	/**
	 * 修改
	 * @return_type: 
	 */
	public String update(){
		sysCountService.add(sysCount);
		sysCount = null;
		return openList();
	}
	
	
	@Override
	public Object getModel() {
		return sysCount;
	}
	@Override
	public void prepare() throws Exception {
		if(sysCount ==null){
			sysCount = new SysCount();
		}
	}

	public SysCount getSysCount() {
		return sysCount;
	}

	public void setSysCount(SysCount sysCount) {
		this.sysCount = sysCount;
	}

	public Result<SysCount> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<SysCount> pageResult) {
		this.pageResult = pageResult;
	}

	public List<SysCount> getSysCountAllList() {
		return sysCountAllList;
	}

	public void setSysCountAllList(List<SysCount> sysCountAllList) {
		this.sysCountAllList = sysCountAllList;
	}
	
}
